local hx__xiayuan = fk.CreateSkill({
  name = "hx__xiayuan",
})

hx__xiayuan:addEffect(fk.DamageInflicted, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__xiayuan.name) and player:usedSkillTimes(hx__xiayuan.name) < 1
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = hx__xiayuan.name, prompt = "#hx__xiayuan:" .. data.to.id}) then
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local choice = room:askToChoices(to, {
      min_num = 1,
      max_num = 2,
      choices = {"hx__xiayuan_draw","hx__xiayuan_recover"},
      skill_name = hx__xiayuan.name,
      cancelable = true,
      prompt = "你可选择任意选项执行，然后本回合获得【固垒】（每选择一项，此伤害便+1）",
    })
    if choice then
      if not to:hasSkill("hx__gulei") then
        room:handleAddLoseSkills(to, "hx__gulei", nil, true)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(to, "-hx__gulei")
        end)
      end
      if table.contains(choice,"hx__xiayuan_recover") then
        data:changeDamage(1)
      end
      if table.contains(choice,"hx__xiayuan_draw") then
        data:changeDamage(1)
      end
      if table.contains(choice,"hx__xiayuan_draw") then
        local x = math.max(to.maxHp - to:getHandcardNum(), 0)
        to:drawCards(x,hx__xiayuan.name)
      end
      if table.contains(choice,"hx__xiayuan_recover") then
        room:recover({num = 2, who = to, skillName = hx__xiayuan.name})
      end
    end
  end,
})


return hx__xiayuan
